package com.func;

import java.util.function.Function;

/**
 * https://zhuanlan.zhihu.com/p/357918015
 * 如何消费一个函数，消费函数需要在参数列表正确地描述函数类型
 *
 * @author: chenhs
 * @date: Created in 10:18 2022/7/12
 **/
public class ConsumeFunction {

    static Two consume(Function<One, Two> function) {
        return function.apply(new One());
    }

    public static void main(String[] args) {
        //普通写法
        Two two = consume(new Function<One, Two>() {
            @Override
            public Two apply(One one) {
                return new Two();
            }
        });

        //lambda写法
        Two two1 = consume(one -> new Two());
    }
}
